﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Services;
namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 交叉方组织管理
/// </summary>
[Route("QHSEOverLappingOrganization/[action]")]
[ApiController]

public class QHSEOverLappingOrganizationController : ControllerBase
{
    private readonly QHSEOverLappingOrganizationService _organizationService;

    public QHSEOverLappingOrganizationController(QHSEOverLappingOrganizationService organizationService)
    {
        _organizationService = organizationService;
    }

    /// <summary>
    /// 组织列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> List()
    {
        List<QHSEOverLappingOrganizationModel> data = await _organizationService.GetAsync();
        return AppResult.Status200OK(data: data);
    }
    /// <summary>
    /// 组织分页查询
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Page([FromQuery] QHSEOverLappingOrganizationPageInputModel model)
    {
        var data = await _organizationService.GetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }
    /// <summary>
    /// id取值
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> GetValue([FromBody] IdInputModel model)
    {
        var data = await _organizationService.GetByIdAsync(model);
        return AppResult.Status200OK(data: data);
    }

    [HttpGet]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> TreeList([FromQuery] QHSEOverLappingOrganizationInputModel input)
    {
        List<QHSEOverLappingOrganizationTreeNodeModel> data = await _organizationService.GetAsync(input);
        return AppResult.Status200OK(data: data);
    }

    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Add([FromBody] QHSEOverLappingOrganizationModel model)
    {
        await _organizationService.AddAsync(model);
        return AppResult.Status200OK("新增成功");
    }

    /// <summary>
    /// 组织树
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Tree([FromBody] IdInputModel idInputModel)
    {
        List<AntTreeNode> data = new List<AntTreeNode>();
        data = await _organizationService.GetTreeAsync();
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 组织编辑
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Edit([FromBody] QHSEOverLappingOrganizationModel model)
    {
        await _organizationService.EditAsync(model);
        return AppResult.Status200OK("更新成功");
    }

    ///// <summary>
    ///// 组织删除
    ///// </summary>
    ///// <param name="models"></param>
    ///// <returns></returns>
    [HttpDelete]
    [CustomAuthorize("hdv_qhse_data")]
    public async Task<AppResult> Delete([FromBody] List<IdInputModel> model)
    {
        await _organizationService.DeleteAsync(model.Select(m => m.Id));
        return AppResult.Status200OK("删除成功");
    }
}

